import CryptoJS from 'crypto-js'

const KEY_IV = CryptoJS.enc.Utf8.parse('1111111111111111') // 必须为16位

const options = {
  iv: KEY_IV,
  mode: CryptoJS.mode.CBC,
  padding: CryptoJS.pad.ZeroPadding
}

export const encryptAES = function (word) {
  const srcs = CryptoJS.enc.Utf8.parse(word)
  const encrypted = CryptoJS.AES.encrypt(srcs, KEY_IV, options)
  return encrypted.toString()
}

export const decryptAES = function (word) {
  const decrypt = CryptoJS.AES.decrypt(word, KEY_IV, options)
  return CryptoJS.enc.Utf8.stringify(decrypt).toString()
}

export const getMD5String = function (string) {
  return CryptoJS.MD5(string).toString().toUpperCase()
}

export const encryptSHA256 = function (string) {
  return CryptoJS.SHA256(string).toString().toLowerCase()
}
